package com.zhaofan.other;



import org.junit.Test;

import java.util.*;

/**
 * https://leetcode-cn.com/problems/path-sum-iii/
 */
public class No437 {
    int pathNumber;

    public int pathSum(TreeNode root, int targetSum) {
        if(root==null) return 0;

        sum(root,targetSum);
        pathSum(root.left,targetSum);
        pathSum(root.right,targetSum);
        return pathNumber;
    }
    public void sum (TreeNode root, int targetSum){
        if(root==null) return;
        targetSum-=root.val;
        if(targetSum==0){
            pathNumber++;
        }
        sum(root.left,targetSum);
        sum(root.right,targetSum);

    }







    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
